#ifndef MYTOOLBUTTON_H
#define MYTOOLBUTTON_H

#include <QToolButton>
#include <QEvent>
#include <QVBoxLayout>
#include <QSlider>
#include <QString>
#include <QLabel>
#include <QLineEdit>
#include <QProgressBar>
#include <QMainWindow>
#include "mainwindow.h"
#include "dataprovider.h"
#include "mydisplaywidget.h"

typedef enum
{
    NONE,
    //Menu1
    AUTOMODE,
    MANUALMODE,
    PAUSEMODE3,
    PAUSEMODE2,
    PAUSEMODE1,
    //Menu2
    AUTOHEAT,
    MANUALHEAT,
    //Menu3
    QUICKMODE,
    PRECISEMODE,
    //M4-1
    PUSHAMOUNT,
    PUSHSPEED,
    FACEANGLE,
    //M4-2
    MULTIPRETIME,
    MULTIPREINTENSE,
    MULTITIME,
    MULTIINTENSE,
    SINGLEPRETIME,
    SINGLEPREINTENSE,
    SINGLETIME,
    SINGLEINTENSE,
    //M4-3
    HEATINGTIME,
    //M4-4-1
    TENSIONTES,  //lbs 17/5/5
    TENSIONTESTON,
    TENSIONTESTOFF,
    //M4-4-2
    MANUALSPEED,
    //M4-1-5
    PARAMSET,
    //M4-4-3
    VLIGHT,//lbs 17/5/5
    VLIGHTON,
    VLIGHTOFF,
    //M4-4-4
    MENUALPHA,
    //M4-4-5
    LANGUAGESETTING,
    //M4-4-6
    TIMESETTING,
    //M4-5
    DISCHARGINGCALIB,
    CHANGEPOLE,
    DUSTDETECT,
    SELFCHECK,
    //M4-5-5
    STANDBY,
    POWEROFF,
    //
    SYSINFO



}FunctionButtonType;

class MyToolButton : public QToolButton
{
    Q_OBJECT
public:
    explicit MyToolButton(QWidget *parent = 0);
    ~MyToolButton();

    void setUpWg(QWidget* );
    void setDownWg(QWidget* );
    void setRightWg(QWidget* );
    void setLeftWg(QWidget* );
    void setFirstChildTB(QWidget*);
    void setParentWg(QWidget*);
    void setIfTop(bool);
    void addChildWg(QWidget*);

    void focusLeft();
    void focusUp();
    void focusDown();
    void focusRight();
    void focusChild();
    void focusParent();

    void setCurVal(unsigned int val);
    void setStylePressed();
    void setStyleFocused();
    void setStyleNormal();
    void setStyleNone();
    void setStyleChecked(bool);
    void showChildWgs(bool);
    void setChildDisabled(bool enable);
    void setDynamicID(int id);
    void setIfAdjust(bool);
    void setSlider(QSlider*);
    void setFunctionType(FunctionButtonType);
    void setInitial(QString,qreal,qreal,qreal,qreal);    
    void setMyDisplayWg(MyDisplayWidget* mdwg);
    void setRootWindow(QMainWindow* mw);
    void setDataProvider(DataProvider* dp);
    void setChildSelected(QWidget * selWg);
    QWidget * getChildSelected();
    FunctionButtonType getFunctionButtonType();

    void setupSelectedButton();
    void setSelected(bool enable);


    void setPerm(bool enable); //权限


    //void setButtonText(QString text);  //lbs 2017/4/21

private:
    void SetIniCfgVal();
    void GetIniCfgVal();

protected:
    //void paintEvent(QPaintEvent *);
    void focusInEvent(QFocusEvent *);
    void focusOutEvent(QFocusEvent *);
    bool eventFilter(QObject*, QEvent *);
    void keyPressEvent(QKeyEvent *);
    void keyReleaseEvent(QKeyEvent *e);
    void enterFunction();


    //bool eventFilter(QObject *, QEvent *);
private:
    QWidget* upWg;
    QWidget* downWg;
    QWidget* leftWg;
    QWidget* rightWg;
    QWidget* slectedChildWg;

    QWidget* parentWg;
    QList<QWidget*> childWgs;
    QProgressBar* valProg;

    FunctionButtonType functionType;

    QString pressedStyle;
    QString normalStyle;
    QString focusedStyle;

    qreal adjValueDefault;
    qreal adjCurrentVal;
    qreal adjMaxVal;
    qreal adjMinVal;
    qreal interval;
    QString adjustName;
    QLabel* textW;
    QLabel* selectICO;  //lbs-2017-4-25
    MyDisplayWidget* mdwg;
    QMainWindow* rootWin;


    bool ifTop;
    int dynamicID;
    DataProvider* dp;
    bool my_Permissions;  //true is admin Permissions , default set false;
    bool my_keyDisenable;
    QString my_Password;
    //bool ifAdjust;//
signals:
   void dynamicRefreshUI(int id);
   void Unlock();


public slots:
    
};

#endif // TOPLEVELBUTTON_H
